//
//  SearcherCarCell.m
//  BalanceCar
//
//  Created by 郑信鸿 on 17/6/20.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "SearcherCarCell.h"

@interface SearcherCarCell ()

@property(nonatomic, strong)UIView *backView;

@end

@implementation SearcherCarCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self establishSubViews];

        
    }
    
    return self;
}


- (void)establishSubViews{
    
    self.backView = [[UIView alloc] init];
    self.backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(0);
        make.left.mas_offset(25);
        make.right.mas_offset(-25);
        make.bottom.mas_offset(0);
    }];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"find_listicon_car"]];
    [self.backView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_offset(0);
        make.left.mas_offset(16);
        
    }];
    
    self.carNameLabel = [[UILabel alloc] init];
    self.carNameLabel.textColor = [UIColor colorFromHexCode:@"#333333"];
    [self.backView addSubview:self.carNameLabel];
    [self.carNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_offset(0);
        make.left.mas_equalTo(imageView.mas_right).offset(10);
    }];
    UIButton *linkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [linkBtn setTitle:XHLocalizedString(@"Connect") forState:UIControlStateNormal];
    linkBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
    [linkBtn setTitleColor:[UIColor colorFromHexCode:@"#6cc348"] forState:UIControlStateNormal];
    linkBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.backView addSubview:linkBtn];
    [linkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_offset(0);
        make.right.mas_offset(-16);
        make.width.height.mas_offset(50);
    }];
    linkBtn.layer.borderWidth = 5.0f;
    linkBtn.layer.borderColor = [UIColor colorFromHexCode:@"#6cc348"].CGColor;
    linkBtn.layer.masksToBounds = YES;
    linkBtn.layer.cornerRadius = 25;
    [linkBtn addTarget:self action:@selector(linkAction:) forControlEvents:UIControlEventTouchUpInside];
    self.line = [[SeparateLineView alloc] init];
    [self.backView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.mas_offset(0);
        make.bottom.mas_offset(-0.5);
        make.height.mas_offset(0.5);
        
    }];
    
}




//创建全部半弧形
- (void)setAllCorner{
    
    self.backView.layer.cornerRadius = 5.0;
    self.backView.layer.masksToBounds = YES;
    
}


- (void)setNoCorner{
    
    CGRect rect = CGRectMake(0, 0, kUIScreenWidth - 50,70 );
    UIBezierPath *berzierPath = [UIBezierPath bezierPathWithRect:rect];
    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
    shape.frame = rect;
    shape.path = berzierPath.CGPath;
    
    self.backView.layer.mask = shape;
    
}
//创建上半部
- (void)setTopCorner{
    CGRect rect = CGRectMake(0, 0, kUIScreenWidth - 50,70 );
    UIBezierPath *berzierPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
    shape.frame = rect;
    shape.path = berzierPath.CGPath;
    
    self.backView.layer.mask = shape;
    
}

//创建下半部
- (void)setBottomCorner{
    
    CGRect rect = CGRectMake(0, 0, kUIScreenWidth - 50,70);
    UIBezierPath *berzierPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
    shape.frame = rect;
    shape.path = berzierPath.CGPath;
    
    self.backView.layer.mask = shape;
    
}

- (void)linkAction:(UIButton *)button{
    if ([_delegate respondsToSelector:@selector(searchCarCell:WithModel:)]){
        
        [_delegate searchCarCell:self WithModel:nil];
        
    }
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
